var supplyPhone ;
$(function(){
    $.ajax({
        url:server_url + "/rest/product/getSkuProductInfo.do?id="+params()['id']+"&random="+Math.random(),
        success:function(data){
            console.log(data)
            $("#img1 img").attr("src",data.data.picturePath1);
            $("#img2 img").attr("src",data.data.picturePath2);
            $("#img3 img").attr("src",data.data.picturePath3);
            $("#productName").text(data.data.productName);
            $("#productPrice").text("¥" + data.data.price + "/头");
            $("#cate").html("类别：" + data.data.specName + "<span>" + approve(data.data.approveStatus) + "</span>");
            $("#overPlus").text("库存：" + data.data.overPlusNum + "头");
            $("#remark").text("备注：" + data.data.remark);
            $("#id").text("编号：" + data.data.id + "头");
            $("#supply").html("<strong>货主：" + data.data.supplyName + "</strong>" + data.data.addTime.substring(0, 10) + "");
            $("#supplyPhone").text(data.data.supplyPhone);
            supplyPhone =data.data.supplyPhone;
        }
    });

    $("#cancel").click(offShelf)
    $("#confirm").click(offShelf)

    function offShelf(){
        $.ajax({
            url:server_url + '/rest/staff/offShelf.do'+"?random="+Math.random(),
            data:{id:params()['id'],staffId:userid},
            success:function(data){
                easyAlert("下架成功");
                window.location.href = '/LianniuWeb/staff/index.do';
            }
        })
    }

    $("#change").click(function(){
        if($("#price").val() == ""){
            easyAlert("请输入价格")
            return
        }
        if(!isPriceNumber($("#price").val())){
            easyAlert("请输入正确的价格")
            return
        }
        if($("#stock").val() == ""){
            easyAlert("请输入库存")
            return
        }
        if(!isInt($("#stock").val())){
            easyAlert("请输入正确的库存")
            return
        }
        $.ajax({
            url:server_url + '/rest/staff/updateSku.do'+"?random="+Math.random(),
            data:{id:params()['id'],price:$("#price").val(),stock:$("#stock").val(),userId:userid},
            success:function(data){
                easyAlert("更新成功！");
                window.location.href = '/LianniuWeb/staff/productDetail.do?id='+ params()['id']
            }
        })
    })
})
function call(){
    window.location.href = "tel:"+supplyPhone;
}
function approve(status){
    if(status == '1'){
        return "审核中"
    }
    if(status == '2'){
        return "审核不通过"
    }
    if(status == '3'){
        return "审核通过"
    }
    return "审核中"
}